#pragma once

#include <string>
#include <fstream>
#include <Windows.h>

///#include "Common.h"

#ifdef _UNICODE
typedef std::wstring _tstring;
typedef std::wfstream _tfstream;
#else
typedef std::string _tstring;
typedef std::fstream _tfstream;
#endif


enum  LOG_LEVEL
{
	LOGGER_INFO = 0x1, 
	LOGGER_WARN = 0x2,
	LOGGER_ERR = 0x4,
	LOGGER_FATAL = 0x8,
};

//#define DISALLOW_COPY_AND_ASSIGN(FileLogger);\	
//		FileLogger(const FileLogger &);		\
//		FileLogger &operator =(const FileLogger &)

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
	TypeName(const TypeName&);               \
	TypeName operator=(const TypeName&)

class FileLogger
{
protected:
	explicit FileLogger(const char *filename);

public:
	static FileLogger *GetInstance();
	~FileLogger(void);
	void Append(TCHAR * mes);
	void Log(TCHAR* fmt, ...);
	void Log(int level, TCHAR* fmt, ...);
	void Dump(const BYTE* buffer, size_t length);

protected:
	void Log(int level, va_list& list, TCHAR* fmt);
	_tstring GetDateTimeString();
	_tstring LogLevelToString(int level);

private:
	static FileLogger *m_pFileLogger;
	FILE *m_pLogFile;
	CCriticalSection m_logCS;
	TCHAR m_sMutexName[MAX_PATH];
	SYSTEMTIME m_LastSystime;
	DISALLOW_COPY_AND_ASSIGN(FileLogger);
protected:
	void RemoveOldLog(int timeoutDays);
};

